// index.js
const {request} = require('../../utils/util.js')
Component({
  data: {
    title: wx.getStorageSync('sysname')+"-公告",
    list:[],
    page:1,
    pages:1
  },
  methods: {
    onLoad: function () {
      this.getList()
    },
    getList(){
      wx.showLoading({
        title: '加载中',
      })
      let that = this
      let page = that.data.page
      let list = that.data.list
      request('GET', 'api.Notice/getList', {
        page:page
      }).then(res => {
          if(res.code==1){
            let data = res.data.list
            list = list.concat(data)
            that.setData({
              list:list,
              page:page+1,
              pages:res.data.page.pages
            })
          }else{
            wx.showToast({
              title: res.info,
              icon: 'none',
              duration: 2000
            })
          }
        wx.hideLoading()
          }).catch(err => {
            console.error('Error:', err);
          });
    },
    bindscrolltolower(){
      console.log('scrolltolower')
      if(this.data.page>this.data.pages){
        wx.showToast({
          title: '没有更多了',
          icon: 'none',
          duration: 1000
        })
        return
      }else{
        this.getList()
      }

    },
    toDeatil(e){
      console.log("toDeatil",e)
      let id = e.currentTarget.dataset.id
      wx.navigateTo({
       url: '/pages/detail/detail?id='+id,
     })
    }




  },
})
